﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.Core.DomainModel;

namespace MethodWorx.CMS.Membership
{
    public class UserRepository : QueryableRepository<User>, IUserRepository
    {
        public UserRepository(IQueryable<User> source)
            : base(source)
        {
        }
        
        public User FindByName(string username)
        {
            return this.source.FirstOrDefault(u => u.Username == username);
        }

        public IEnumerable<User> GetUsersByUserType(UserType userType)
        {
            return this.source.Where(u => u.UserType == userType);
        }

        public override void Update(User entity)
        {
            throw new NotImplementedException();
        }
        public override void Insert(User entity)
        {
            throw new NotImplementedException();
        }
        public override void Delete(User entity)
        {
            throw new NotImplementedException();
        }



        public IEnumerable<string> GetAttributes(UserType userType)
        {
            return this.GetUsersByUserType(userType).SelectMany(u => u.Attributes.Values).Distinct();
        }
    }
}
